home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decoderpza.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  18KB  |  538 lines

  1. /*
  2. sc:c/sc opt txt/DecodeRPZA.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "YUV.h"
  7.  
  8. struct RPZAData {
  9.   uchar gray;
  10.   uchar *rngLimit;
  11.   struct RGBTriple *cmap;
  12. };
  13.  
  14. /* /// "blockInc" */
  15. #define blockInc(x,y,xmax,im0,im1,im2,im3,binc,rinc) { \
  16.   x+=4;                                                \
  17.   im0+=binc;                                           \
  18.   im1+=binc;                                           \
  19.   im2+=binc;                                           \
  20.   im3+=binc;                                           \
  21.   if (x>=xmax) {                                       \
  22.     x=0;                                               \
  23.     y+=4;                                              \
  24.     im0+=rinc;                                         \
  25.     im1+=rinc;                                         \
  26.     im2+=rinc;                                         \
  27.     im3+=rinc;                                         \
  28.   }                                                    \
  29. }
  30. /* \\\ */
  31.  
  32. /* /// "rpzargbC1" */
  33. #define rpzargbC1(ip,r,g,b) {    \
  34.   ip[ 0]=ip[ 3]=ip[ 6]=ip[ 9]=r; \
  35.   ip[ 1]=ip[ 4]=ip[ 7]=ip[10]=g; \
  36.   ip[ 2]=ip[ 5]=ip[ 8]=ip[11]=b; \
  37. }
  38. /* \\\ */
  39.  
  40. /* /// "rpzargbC4" */
  41. #define rpzargbC4(ip,r,g,b,mask) {                                   \
  42.   ulong idx;                                                         \
  43.   idx=(mask>>6) & 0x03; ip[ 0]=r[idx]; ip[ 1]=g[idx]; ip[ 2]=b[idx]; \
  44.   idx=(mask>>4) & 0x03; ip[ 3]=r[idx]; ip[ 4]=g[idx]; ip[ 5]=b[idx]; \
  45.   idx=(mask>>2) & 0x03; ip[ 6]=r[idx]; ip[ 7]=g[idx]; ip[ 8]=b[idx]; \
  46.   idx= mask     & 0x03; ip[ 9]=r[idx]; ip[10]=g[idx]; ip[11]=b[idx]; \
  47. }
  48. /* \\\ */
  49.  
  50. /* /// "rpzargbC16" */
  51. #define rpzargbC16(ip,r,g,b) {           \
  52.   ip[ 0]=r[0]; ip[ 1]=g[0]; ip[ 2]=b[0]; \
  53.   ip[ 3]=r[1]; ip[ 4]=g[1]; ip[ 5]=b[1]; \
  54.   ip[ 6]=r[2]; ip[ 7]=g[2]; ip[ 8]=b[2]; \
  55.   ip[ 9]=r[3]; ip[10]=g[3]; ip[11]=b[3]; \
  56.   r+=4; g+=4; b+=4;                      \
  57. /*                                    \
  58.   *ip++=*r++; *ip++=*g++; *ip++=*b++; \
  59.   *ip++=*r++; *ip++=*g++; *ip++=*b++; \
  60.   *ip++=*r++; *ip++=*g++; *ip++=*b++; \
  61.   *ip++=*r++; *ip++=*g++; *ip++=*b++; \
  62. */                                    \
  63. }
  64. /* \\\ */
  65.  
  66. /* /// "GetAVRGBColors" */
  67. #define GetAVRGBColors(cA,cB,r,g,b) {          \
  68.   ulong rA, gA, bA, rB, gB, bB, ra, ga, ba;    \
  69.   rA=(cA>>10) & 0x1f; r[3]=(rA<<3) | (rA>>2);  \
  70.   gA=(cA>> 5) & 0x1f; g[3]=(gA<<3) | (gA>>2);  \
  71.   bA= cA & 0x1f;      b[3]=(bA<<3) | (bA>>2);  \
  72.                                                \
  73.   rB=(cB>>10) & 0x1f; r[0]=(rB<<3) | (rB>>2);  \
  74.   gB=(cB>> 5) & 0x1f; g[0]=(gB<<3) | (gB>>2);  \
  75.   bB= cB & 0x1f;      b[0]=(bB<<3) | (bB>>2);  \
  76.                                                \
  77.   ra=(21*rA+11*rB)>>5; r[2]=(ra<<3) | (ra>>2); \
  78.   ra=(11*rA+21*rB)>>5; r[1]=(ra<<3) | (ra>>2); \
  79.                                                \
  80.   ga=(21*gA+11*gB)>>5; g[2]=(ga<<3) | (ga>>2); \
  81.   ga=(11*gA+21*gB)>>5; g[1]=(ga<<3) | (ga>>2); \
  82.                                                \
  83.   ba=(21*bA+11*bB)>>5; b[2]=(ba<<3) | (ba>>2); \
  84.   ba=(11*bA+21*bB)>>5; b[1]=(ba<<3) | (ba>>2); \
  85. }
  86. /* \\\ */
  87.  
  88. /* /// "DecodeRPZAtoRGB()" */
  89. __asm void DecodeRPZAtoRGB(REG(a0) uchar *from,
  90.                            REG(a1) uchar *to,
  91.                            REG(d0) ulong width,
  92.                            REG(d1) ulong height,
  93.                            REG(d2) ulong encSize,
  94.                            REG(a2) struct RPZAData *spec)
  95. {
  96.   ulong code;
  97.   uchar *im0, *im1, *im2, *im3;
  98.   long rowInc, len, x, y;
  99.   const long blockInc=12;
  100.  
  101.   from++;
  102.   len=get24(from);
  103.   if (len!=encSize) return;
  104.   len-=4;
  105.  
  106.   rowInc=width*3;
  107.   im0=to;
  108.   im1=im0+rowInc;
  109.   im2=im1+rowInc;
  110.   im3=im2+rowInc;
  111.   rowInc=width*9;
  112.   x=0;
  113.   y=0;
  114.  
  115.   while(len>0) {
  116.     code=*from++;
  117.     len--;
  118.     if ((code>=0xa0) && (code<=0xbf)) {
  119.       ulong color, skip;
  120.       uchar r, g, b;
  121.       color=get16(from);
  122.       len-=2;
  123.       skip=code-0x9f;
  124.       ColorToRGB(color,r,g,b);
  125.       while(skip--) {
  126.         uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  127.         rpzargbC1(ip0,r,g,b);
  128.         rpzargbC1(ip1,r,g,b);
  129.         rpzargbC1(ip2,r,g,b);
  130.         rpzargbC1(ip3,r,g,b);
  131.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  132.       }
  133.     } else if ((code>=0x80) && (code<=0x9f)) {
  134.       ulong skip=code-0x7f;
  135.       while (skip--) blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  136.     } else if ((code<0x80) || ((code>=0xc0) && (code<=0xdf))) {
  137.       ulong cA, cB;
  138.       if (code>=0xc0) {
  139.         cA=get16(from);
  140.         len-=4;
  141.       } else {
  142.         cA=(code<<8) | *from++;
  143.         len-=3;
  144.       }
  145.       cB=get16(from);
  146.       if ((code<0x80) && ((cB & 0x8000)==0)) {
  147.         ulong i, d;
  148.         uchar r[16], g[16], b[16];
  149.         uchar *ip0, *ip1, *ip2, *ip3, *tr, *tg, *tb;
  150.         ColorToRGB(cA,r[0],g[0],b[0]);
  151.         ColorToRGB(cB,r[1],g[1],b[1]);
  152.         for (i=2; i<16; i++) {
  153.           d=get16(from);
  154.           ColorToRGB(d,r[i],g[i],b[i]);
  155.         }
  156.         len-=28;
  157.         ip0=im0; ip1=im1; ip2=im2; ip3=im3;
  158.         tr=r; tg=g; tb=b;
  159.         rpzargbC16(ip0,tr,tg,tb);
  160.         rpzargbC16(ip1,tr,tg,tb);
  161.         rpzargbC16(ip2,tr,tg,tb);
  162.         rpzargbC16(ip3,tr,tg,tb);
  163.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  164.       } else {
  165.         ulong mCnt;
  166.         uchar r[4], g[4], b[4];
  167.         if (code<0x80) mCnt=1; else mCnt=code-0xbf;
  168.         GetAVRGBColors(cA,cB,r,g,b);
  169.         while (mCnt--) {
  170.           uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  171.           ulong mask;
  172.           mask=from[0];
  173.           rpzargbC4(ip0,r,g,b,mask);
  174.           mask=from[1];
  175.           rpzargbC4(ip1,r,g,b,mask);
  176.           mask=from[2];
  177.           rpzargbC4(ip2,r,g,b,mask);
  178.           mask=from[3];
  179.           rpzargbC4(ip3,r,g,b,mask);
  180.           blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  181.           from+=4;
  182.           len-=4;
  183.         }
  184.       }
  185.     }
  186.   }
  187. }
  188. /* \\\ */
  189.  
  190. /* /// "rpzaC1" */
  191. #define rpzaC1(ip0,ip1,ip2,ip3,c) { \
  192.   ip0[0]=ip0[1]=ip0[2]=ip0[3]=c;    \
  193.   ip1[0]=ip1[1]=ip1[2]=ip1[3]=c;    \
  194.   ip2[0]=ip2[1]=ip2[2]=ip2[3]=c;    \
  195.   ip3[0]=ip3[1]=ip3[2]=ip3[3]=c;    \
  196. }
  197. /* \\\ */
  198.  
  199. /* /// "rpzaC4" */
  200. #define rpzaC4(ip,c,mask) {    \
  201.   ip[0]=c[((mask>>6) & 0x03)]; \
  202.   ip[1]=c[((mask>>4) & 0x03)]; \
  203.   ip[2]=c[((mask>>2) & 0x03)]; \
  204.   ip[3]=c[( mask     & 0x03)]; \
  205. }
  206. /* \\\ */
  207.  
  208. /* /// "rpzaC16" */
  209. #define rpzaC16(ip0,ip1,ip2,ip3,c) {                  \
  210.   *ip0++=*c++; *ip0++=*c++; *ip0++=*c++; *ip0++=*c++; \
  211.   *ip1++=*c++; *ip1++=*c++; *ip1++=*c++; *ip1++=*c++; \
  212.   *ip2++=*c++; *ip2++=*c++; *ip2++=*c++; *ip2++=*c++; \
  213.   *ip3++=*c++; *ip3++=*c++; *ip3++=*c++; *ip3++=*c;   \
  214. }
  215. /* \\\ */
  216.  
  217. /* /// "GetAVColors" */
  218. #define GetAVColors(cA,cB,c) {         \
  219.   ulong rA5, gA5, bA5, rB5, gB5, bB5;  \
  220.   ulong r05, g05, b05, r15, g15, b15;  \
  221.                                        \
  222.   rA5=(cA >> 10) & 0x1f;               \
  223.   gA5=(cA >>  5) & 0x1f;               \
  224.   bA5= cA & 0x1f;                      \
  225.                                        \
  226.   rB5=(cB >> 10) & 0x1f;               \
  227.   gB5=(cB >>  5) & 0x1f;               \
  228.   bB5= cB & 0x1f;                      \
  229.                                        \
  230.   r05=(21*rA5+11*rB5) >> 5;            \
  231.   r15=(11*rA5+21*rB5) >> 5;            \
  232.                                        \
  233.   g05=(21*gA5+11*gB5) >> 5;            \
  234.   g15=(11*gA5+21*gB5) >> 5;            \
  235.                                        \
  236.   b05=(21*bA5+11*bB5) >> 5;            \
  237.   b15=(11*bA5+21*bB5) >> 5;            \
  238.                                        \
  239.   if (gray) {                          \
  240.     c[0]=RGB5toGray(rB5,gB5,bB5);      \
  241.     c[1]=RGB5toGray(r15,g15,b15);      \
  242.     c[2]=RGB5toGray(r05,g05,b05);      \
  243.     c[3]=RGB5toGray(rA5,gA5,bA5);      \
  244.   } else {                             \
  245.     c[0]=RGBto332(rB5,gB5,bB5,scale5); \
  246.     c[1]=RGBto332(r15,g15,b15,scale5); \
  247.     c[2]=RGBto332(r05,g05,b05,scale5); \
  248.     c[3]=RGBto332(rA5,gA5,bA5,scale5); \
  249.   }                                    \
  250. }
  251. /* \\\ */
  252.  
  253. /* /// "DecodeRPZAto332()" */
  254. __asm void DecodeRPZAto332(REG(a0) uchar *from,
  255.                            REG(a1) uchar *to,
  256.                            REG(d0) ulong width,
  257.                            REG(d1) ulong height,
  258.                            REG(d2) ulong encSize,
  259.                            REG(a2) struct RPZAData *spec)
  260. {
  261.   ulong code;
  262.   uchar *im0, *im1, *im2, *im3;
  263.   long rowInc, len, x, y;
  264.   const long blockInc=4;
  265.   uchar gray=spec->gray;
  266.  
  267.   from++;
  268.   len=get24(from);
  269.   if (len!=encSize) return;
  270.   len-=4;
  271.  
  272.   rowInc=width;
  273.   im0=to;
  274.   im1=im0+rowInc;
  275.   im2=im1+rowInc;
  276.   im3=im2+rowInc;
  277.   rowInc=width*3;
  278.   x=0;
  279.   y=0;
  280.  
  281.   while(len>0) {
  282.     code=*from++;
  283.     len--;
  284.     if ((code>=0xa0) && (code<=0xbf)) {
  285.       ulong color, skip;
  286.       color=get16(from);
  287.       len-=2;
  288.       skip=code-0x9f;
  289.       if (gray) {ColorTo332Gray(color,color);} else {ColorTo332(color,color);}
  290.       while(skip--) {
  291.         uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  292.         rpzaC1(ip0,ip1,ip2,ip3,color);
  293.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  294.       }
  295.     } else if ((code>=0x80) && (code<=0x9f)) {
  296.       ulong skip=code-0x7f;
  297.       while (skip--) blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  298.     } else if ((code<0x80) || ((code>=0xc0) && (code<=0xdf))) {
  299.       ulong cA, cB;
  300.       if (code>=0xc0) {
  301.         cA=get16(from);
  302.         len-=4;
  303.       } else {
  304.         cA=(code<<8) | *from++;
  305.         len-=3;
  306.       }
  307.       cB=get16(from);
  308.       if ((code<0x80) && ((cB & 0x8000)==0)) {
  309.         ulong i, d, c[16];
  310.         ulong *clr;
  311.         uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  312.         if (gray) {
  313.           ColorTo332Gray(cA,c[0]);
  314.           ColorTo332Gray(cB,c[1]);
  315.           for (i=2; i<16; i++) {
  316.             d=get16(from);
  317.             ColorTo332Gray(d,c[i]);
  318.           }
  319.         } else {
  320.           ColorTo332(cA,c[0]);
  321.           ColorTo332(cB,c[1]);
  322.           for (i=2; i<16; i++) {
  323.             d=get16(from);
  324.             ColorTo332(d,c[i]);
  325.           }
  326.         }
  327.         len-=28;
  328.         clr=c;
  329.         rpzaC16(ip0,ip1,ip2,ip3,clr);
  330.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  331.       } else {
  332.         ulong mCnt, c[4];
  333.         if (code<0x80) mCnt=1; else mCnt=code-0xbf;
  334.         GetAVColors(cA,cB,c);
  335.         while (mCnt--) {
  336.           uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  337.           ulong mask;
  338.           mask=from[0];
  339.           rpzaC4(ip0,c,mask);
  340.           mask=from[1];
  341.           rpzaC4(ip1,c,mask);
  342.           mask=from[2];
  343.           rpzaC4(ip2,c,mask);
  344.           mask=from[3];
  345.           rpzaC4(ip3,c,mask);
  346.           blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  347.           from+=4;
  348.           len-=4;
  349.         }
  350.       }
  351.     }
  352.   }
  353. }
  354. /* \\\ */
  355.  
  356. /* /// "DecodeRPZAto332Dith()" */
  357. __asm void DecodeRPZAto332Dith(REG(a0) uchar *from,
  358.                                REG(a1) uchar *to,
  359.                                REG(d0) ulong width,
  360.                                REG(d1) ulong height,
  361.                                REG(d2) ulong encSize,
  362.                                REG(a2) struct RPZAData *spec)
  363. {
  364.   ulong code;
  365.   uchar *im0, *im1, *im2, *im3;
  366.   long rowInc, len, x, y;
  367.   const long blockInc=4;
  368.   uchar gray=spec->gray;
  369.   uchar *rngLimit=spec->rngLimit;
  370.   struct RGBTriple *cmap=spec->cmap;
  371.  
  372.   from++;
  373.   len=get24(from);
  374.   if (len!=encSize) return;
  375.   len-=4;
  376.  
  377.   rowInc=width;
  378.   im0=to;
  379.   im1=im0+rowInc;
  380.   im2=im1+rowInc;
  381.   im3=im2+rowInc;
  382.   rowInc=width*3;
  383.   x=0;
  384.   y=0;
  385.  
  386.   while(len>0) {
  387.     code=*from++;
  388.     len--;
  389.     if ((code>=0xa0) && (code<=0xbf)) {
  390.       ulong color, skip;
  391.       long re, ge, be, r, g, b, col;
  392.       color=get16(from);
  393.       len-=2;
  394.       skip=code-0x9f;
  395.       ColorToRGB(color,r,g,b);
  396.       while(skip--) {
  397.         uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  398.         re=ge=be=0;
  399.         DitherGetRGB(r,g,b,re,ge,be,col); ip0[0]=col;
  400.         DitherGetRGB(r,g,b,re,ge,be,col); ip0[1]=col;
  401.         DitherGetRGB(r,g,b,re,ge,be,col); ip1[1]=col;
  402.         DitherGetRGB(r,g,b,re,ge,be,col); ip1[0]=col;
  403.         DitherGetRGB(r,g,b,re,ge,be,col); ip2[0]=col;
  404.         DitherGetRGB(r,g,b,re,ge,be,col); ip3[0]=col;
  405.         DitherGetRGB(r,g,b,re,ge,be,col); ip3[1]=col;
  406.         DitherGetRGB(r,g,b,re,ge,be,col); ip2[1]=col;
  407.         DitherGetRGB(r,g,b,re,ge,be,col); ip2[2]=col;
  408.         DitherGetRGB(r,g,b,re,ge,be,col); ip3[2]=col;
  409.         DitherGetRGB(r,g,b,re,ge,be,col); ip3[3]=col;
  410.         DitherGetRGB(r,g,b,re,ge,be,col); ip2[3]=col;
  411.         DitherGetRGB(r,g,b,re,ge,be,col); ip1[3]=col;
  412.         DitherGetRGB(r,g,b,re,ge,be,col); ip1[2]=col;
  413.         DitherGetRGB(r,g,b,re,ge,be,col); ip0[2]=col;
  414.         DitherGetRGB(r,g,b,re,ge,be,col); ip0[3]=col;
  415.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  416.       }
  417.     } else if ((code>=0x80) && (code<=0x9f)) {
  418.       ulong skip=code-0x7f;
  419.       while (skip--) blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  420.     } else if ((code<0x80) || ((code>=0xc0) && (code<=0xdf))) {
  421.       ulong cA, cB;
  422.       if (code>=0xc0) {
  423.         cA=get16(from);
  424.         len-=4;
  425.       } else {
  426.         cA=(code<<8) | *from++;
  427.         len-=3;
  428.       }
  429.       cB=get16(from);
  430.       if ((code<0x80) && ((cB & 0x8000)==0)) {
  431.         uchar *cptr=from;
  432.         uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  433.         long re=0, ge=0, be=0, ra, ga, ba, col;
  434.         from+=28;
  435.         len-=28;
  436.         ColorToRGB(cA,ra,ga,ba);
  437.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[0]=col;
  438.         ColorToRGB(cB,ra,ga,ba);
  439.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[1]=col;
  440.         cA=(cptr[6]<<8) | (cptr[7]);
  441.         ColorToRGB(cA,ra,ga,ba);
  442.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[1]=col;
  443.         cA=(cptr[4]<<8) | (cptr[5]);
  444.         ColorToRGB(cA,ra,ga,ba);
  445.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[0]=col;
  446.         cA=(cptr[12]<<8) | (cptr[13]);
  447.         ColorToRGB(cA,ra,ga,ba);
  448.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[0]=col;
  449.         cA=(cptr[20]<<8) | (cptr[21]);
  450.         ColorToRGB(cA,ra,ga,ba);
  451.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[0]=col;
  452.         cA=(cptr[22]<<8) | (cptr[23]);
  453.         ColorToRGB(cA,ra,ga,ba);
  454.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[1]=col;
  455.         cA=(cptr[14]<<8) | (cptr[15]);
  456.         ColorToRGB(cA,ra,ga,ba);
  457.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[1]=col;
  458.         cA=(cptr[16]<<8) | (cptr[17]);
  459.         ColorToRGB(cA,ra,ga,ba);
  460.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[2]=col;
  461.         cA=(cptr[24]<<8) | (cptr[25]);
  462.         ColorToRGB(cA,ra,ga,ba);
  463.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[2]=col;
  464.         cA=(cptr[26]<<8) | (cptr[27]);
  465.         ColorToRGB(cA,ra,ga,ba);
  466.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[3]=col;
  467.         cA=(cptr[18]<<8) | (cptr[19]);
  468.         ColorToRGB(cA,ra,ga,ba);
  469.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[3]=col;
  470.         cA=(cptr[10]<<8) | (cptr[11]);
  471.         ColorToRGB(cA,ra,ga,ba);
  472.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[3]=col;
  473.         cA=(cptr[8]<<8) | (cptr[9]);
  474.         ColorToRGB(cA,ra,ga,ba);
  475.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[2]=col;
  476.         cA=(cptr[0]<<8) | (cptr[1]);
  477.         ColorToRGB(cA,ra,ga,ba);
  478.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[2]=col;
  479.         cA=(cptr[2]<<8) | (cptr[3]);
  480.         ColorToRGB(cA,ra,ga,ba);
  481.         DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[3]=col;
  482.         blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  483.       } else {
  484.         uchar r[4], g[4], b[4];
  485.         ulong mCnt;
  486.         if (code<0x80) mCnt=1; else mCnt=code-0xbf;
  487.         GetAVRGBColors(cA,cB,r,g,b);
  488.         while (mCnt--) {
  489.           uchar *ip0=im0, *ip1=im1, *ip2=im2, *ip3=im3;
  490.           ulong mask0, mask1, mask2, mask3;
  491.           long idx, re=0, ge=0, be=0, ra, ga, ba, col;
  492.           mask0=from[0];
  493.           mask1=from[1];
  494.           mask2=from[2];
  495.           mask3=from[3];
  496.           from+=4;
  497.           len-=4;
  498.           idx=(mask0>>6) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  499.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[0]=col;
  500.           idx=(mask0>>4) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  501.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[1]=col;
  502.           idx=(mask1>>4) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  503.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[1]=col;
  504.           idx=(mask1>>6) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  505.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[0]=col;
  506.           idx=(mask2>>6) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  507.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[0]=col;
  508.           idx=(mask3>>6) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  509.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[0]=col;
  510.           idx=(mask3>>4) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  511.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[1]=col;
  512.           idx=(mask2>>4) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  513.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[1]=col;
  514.           idx=(mask2>>2) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  515.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[2]=col;
  516.           idx=(mask3>>2) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  517.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[2]=col;
  518.           idx= mask3     & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  519.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip3[3]=col;
  520.           idx= mask2     & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  521.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip2[3]=col;
  522.           idx= mask1     & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  523.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[3]=col;
  524.           idx=(mask1>>2) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  525.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip1[2]=col;
  526.           idx=(mask0>>2) & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  527.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[2]=col;
  528.           idx= mask0     & 0x03; ra=r[idx]; ga=g[idx]; ba=b[idx];
  529.           DitherGetRGB(ra,ga,ba,re,ge,be,col); ip0[3]=col;
  530.           blockInc(x,y,width,im0,im1,im2,im3,blockInc,rowInc);
  531.         }
  532.       }
  533.     }
  534.   }
  535. }
  536. /* \\\ */
  537.  
  538.